package top.saplf.sileny.base.ui

import android.os.Bundle
import android.support.annotation.LayoutRes
import android.support.v4.app.Fragment
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import com.hannesdorfmann.mosby3.mvi.MviFragment
import com.hannesdorfmann.mosby3.mvi.MviPresenter
import com.hannesdorfmann.mosby3.mvp.MvpView

/**
 * @author Saplf
 */
abstract class SilenyFragment : Fragment() {
    @LayoutRes private var mLayoutRes: Int = View.NO_ID
        get() = onLayoutRes()

    open fun onLayoutRes(): Int = View.NO_ID

    override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?): View? {
        if (mLayoutRes == View.NO_ID) return null
        return inflater.inflate(mLayoutRes, container, false)
    }
}

abstract class SilenyMviFragment<V : MvpView, P : MviPresenter<V, *>> : MviFragment<V, P>() {
    @LayoutRes private var mLayoutRes: Int = View.NO_ID
        get() = onLayoutRes()

    open fun onLayoutRes(): Int = View.NO_ID

    override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?): View? {
        if (mLayoutRes == View.NO_ID) return null
        return inflater.inflate(mLayoutRes, container, false)
    }
}
